import * as dictionaryService from 'services/dictionary'

export default {
  namespace: 'dictionary',

  state: {
    dic: {},
  },

  effects: {
    * queryBySn ({payload}, {call, put}) {
      const response = yield call(dictionaryService.queryBySn, payload)
      const data = response
      if (response.code === 0 && data) {
        yield put({
          type: 'save',
          payload: {
            ...data,
          },
        })
      } else {
        throw response
      }
    },
  },

  reducers: {
    save (state, {payload}) {
      const {dic} = state
      const newDic = {
        ...dic,
        ...payload.dic,
      }
      return {
        dic: newDic,
      }
    },
  },
}
